#ifndef SM4ENCRYPTMGR_H
#define SM4ENCRYPTMGR_H

#include "sm4.h"
#include <string>
#include <stdio.h>
using namespace std;

namespace A {
namespace B {

    class SM4EncryptMgr
    {
    public:
         bool encryptFile(const string& infilename, const string& outfilename);
         bool decryptFile(const string& infilename, const string& outfilename);
         bool isEncryptFile(const std::string& file);
         char* getDecryptDataFromFile(const string& infilename, long& filelength);

         //Note!!! only for common string, binary not adapt
         bool encryptStr(const string& in, string& res);
         bool dencryptStr(const string& in, string& res);

    private:
         bool encryptData(const unsigned char* in, unsigned char* out, long buflength);
         bool decryptData(const unsigned char* in, unsigned char* out, long buflength, long& filelength);
         long resizeEncryptLength(long length);
         bool setEncryptFileBuf(unsigned char* buf, FILE* file, long filelength, long buflength);
         bool addMD5SumHead(FILE *file, unsigned char *buf, long buflength);
         bool chkMD5(const unsigned char *filebuf, long filelength);

    public:
        SM4EncryptMgr(): mCycle(1)
        {}

    private:
        SM4 m_encryptProto;
        const int mCycle;
        static unsigned char mGenerateKey[SM4_BLOCK_SIZE];

    };
}
}
#endif // SM4ENCRYPTMGR_H
